import Vue from 'vue'
import App from './App'
import GoEasy from '@/uni_modules/GOEASY-IM/js_sdk/goeasy-2.6.1.esm.min.js'
import appInfo from 'common/appInfo.js'
// vuex
import store from './store'

// 工具函数
import utils from './common/utils';
Vue.prototype.$utils = utils;

// 引入全局uView
import uView from '@/uni_modules/uview-ui'

import mixin from './common/mixin'

// 全局分享
const $x = {}; 
Vue.prototype.$x = $x;
let share=require('./common/share.js');
Vue.mixin(share);

Vue.prototype.$onLaunched = new Promise(resolve => {
    Vue.prototype.$isResolve = resolve;
})

Vue.prototype.$store = store

Vue.config.productionTip = false

App.mpType = 'app'
Vue.use(uView)

Vue.mixin(mixin)

const app = new Vue({
    store,
    ...App
})


app.$mount()
const goEasy = GoEasy.getInstance({
    host: appInfo.goEasy.host,	//应用所在的区域地址: [hangzhou.goeasy.io, 新加坡暂不支持IM，敬请期待]
    appkey: appInfo.goEasy.appkey,	// common key,
    modules: ['im'],
    // true表示支持通知栏提醒，false则表示不需要通知栏提醒
    allowNotification: false //仅有效于app,小程序和H5将会被自动忽略
});

goEasy.onClickNotification((message) => {
    let currentUrl;
    const routes = getCurrentPages();

    if (routes && routes.length) {
        const curRoute = routes[routes.length - 1].route;
        const curParam = routes[routes.length - 1].options;
        currentUrl = '/' + curRoute + `?to=${curParam.to}`;
    }

    let newUrl;
    switch (message.toType) {
        case GoEasy.IM_SCENE.PRIVATE:
            newUrl = '/pages/privateChat?to=' + message.senderId;
            break;
        case GoEasy.IM_SCENE.GROUP:
            newUrl = '/pages/groupChat?to=' + message.groupId;
            break;
    }

    if (currentUrl !== newUrl) {
        uni.navigateTo({
            url: newUrl,
        });
    }

});

Vue.prototype.GoEasy = GoEasy;
Vue.prototype.goEasy = goEasy;